import pygame
import os
import random

from numpy.random import randint
from pygame.sprite import Sprite


class Drop(Sprite):
    def __init__(self, screen):
        super(Drop, self).__init__()
        self.screen = screen

        image_path = os.path.join('images', 'mini_drop.bmp')
        self.image = pygame.image.load(image_path)
        self.rect = self.image.get_rect()

        self.rect.x = self.rect.width
        self.rect.y = self.rect.height

        self.x = float(self.rect.x)
        self.y = float(self.rect.y)

        # 雨滴下落速度初始化
        # self.speed = random.random() * 2
        self.speed = randint(1, 3)


    def update(self):
        # 雨滴下落
        self.rect.y += self.speed

        # 触及屏幕,从顶部下落
        screen_rect = self.screen.get_rect()
        if self.rect.y > screen_rect.bottom:
            # self.kill()
            self.rect.y = self.rect.height


    def blitme(self):
        self.screen.blit(self.image, self.rect)
